//
//  BanJiXueShengCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/15.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "BanJiXueShengCell.h"

@implementation BanJiXueShengCell

- (void)awakeFromNib {
    [super awakeFromNib];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
    }
    return self;
}

- (void)initSubView{
    UILabel * contLab = [UILabel new];
    CGFloat W = 1.0/8;
    for (int i = 0; i<8; i++) {
        UILabel *label = [[UILabel alloc]init];
        label.frame = CGRectMake(0, 0, W, 40);
        label.textAlignment = 1;
        label.textColor = TITLECOLOR;
        label.font = [UIFont systemFontOfSize:12];
        [self addSubview:label];
        label.tag = 20+i;
        if (i == 0) {
            contLab = label;
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@0);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
        } else {
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.centerY.equalTo(self.mas_centerY);
                make.width.equalTo(self).multipliedBy(W);
                make.height.mas_equalTo(40);
            }];
            contLab = label;
        }
        if (i==7) {
            label.userInteractionEnabled = YES;
            _button = [UIButton buttonWithType:UIButtonTypeSystem];
            [_button setTitle:@"查看" forState:UIControlStateNormal];
            _button.titleLabel.font = [UIFont systemFontOfSize:12];
            [_button addTarget:self action:@selector(lookUp:) forControlEvents:UIControlEventTouchUpInside];
            [label addSubview:_button];
            [_button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(label.mas_centerY);
                make.centerX.equalTo(label.mas_centerX);
                make.width.equalTo(@40);
                make.height.equalTo(@20);
            }];
        }
    }
    [self.button addTarget:self action:@selector(lookUp:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)lookUp:(UIButton *)sender{
    self.block(self.index);
}
//- (void)reloadViewLayout{
//    CGFloat W = self.frame.size.width/8;
//    for (int i = 0; i<8; i++) {
//        if (i == 7) {
//            _button.frame = CGRectMake(W*i, 0, W, 40);
//        }else{
//            UILabel *label = (UILabel *)[self viewWithTag:i+20];
//            label.frame = CGRectMake(W*i, 0, W, 40);
//        }
//    }
//}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
